package com.rms.hkpc.model;

import com.rms.hkpc.MyApplication;
import com.rms.hkpc.callback.Callback;
import com.rms.hkpc.callback.CallbackWithProgress;
import com.rms.hkpc.model.listener.OnResultListener;
import com.rms.hkpc.model.listener.OnResultProgressListener;
import com.rms.hkpc.util.OKHttpUtil;

import java.io.File;
import java.lang.reflect.Type;

public class VersionModel {
    public void getVersion(final OnResultListener listener, Type typeofT){
        OKHttpUtil.getInstance().getVersion(OKHttpUtil.VERSION_NET_URL + "/api/WebServices/appInfo?applicationId="+ MyApplication.getContext().getPackageName(),
                new Callback() {
                    @Override
                    public void onSuccess(Object obj) {
                        listener.onSuccess(obj);
                    }

                    @Override
                    public void onFailed(Exception e) {
                        listener.onFails(e);
                    }
                },typeofT);
    }

    public void download(String fileName, File file, final OnResultProgressListener listener){
        OKHttpUtil.getInstance().downloadFile(OKHttpUtil.VERSION_NET_URL + "/api/WebServices/download/" + fileName, file,
                new CallbackWithProgress() {
                    @Override
                    public void onSuccess(Object obj) {
                        listener.onSuccess(obj);
                    }

                    @Override
                    public void onFailed(Exception e) {
                        listener.onFails(e);
                    }

                    @Override
                    public void onProgress(int progress) {
                        listener.onProgress(progress);
                    }
                });
    }
}
